<?php
/**
 * @author Mazvv
 * @package Clients
 */
class Clients extends CRM_Controller {
	
	public function __construct(){
		parent::__construct();
		$this->a_identifier = 'clients';
		$this->lang->load('clients');
		$this->load->model('clients_model');
		$this->SetNewToolSize('750x400');
		$this->SetEditToolSize('750x400');
		$this->SetDetailsToolSize('750x400');
		$this->SetFindToolSize('450x200');
		
		
		//$this->a_validation_rules['parent'] = "required";                         
		$this->a_validation_rules['f_name'] = "required";                                   
		$this->a_validation_rules['s_name'] = "required";                         
		$this->a_validation_rules['l_name'] = "required";                           
		$this->a_validation_rules['f_name_lat'] = "required";                             
		$this->a_validation_rules['l_name_lat'] = "required";                    
		$this->a_validation_rules['birthday'] = "required";                
		$this->a_validation_rules['citizenship'] = "required";                   
		//$this->a_validation_rules['passp_seria'] = "required";              
		//$this->a_validation_rules['passp_num'] = "required";              
		$this->a_validation_rules['f_pass_seria'] = "required"; 
		$this->a_validation_rules['f_pass_num'] = "required"; 
		$this->a_validation_rules['f_pass_period'] = "required";
		//$this->a_validation_rules['nal_number']  = "required";           
		//$this->a_validation_rules['_cities_rid'] = "required";                               
		$this->a_validation_rules['adress'] = "required";                               
		$this->a_validation_rules['phones'] = "required";                         
		//$this->a_validation_rules['email'] = "required";             		
		
		$this->a_validation_fields['parent'] = $this->lang->line('PARENT');                         
		$this->a_validation_fields['f_name'] = $this->lang->line('F_NAME');                                   
		$this->a_validation_fields['s_name'] = $this->lang->line('S_NAME');                         
		$this->a_validation_fields['l_name'] = $this->lang->line('L_NAME');                           
		$this->a_validation_fields['f_name_lat'] = $this->lang->line('F_NAME_LAT');                             
		$this->a_validation_fields['l_name_lat'] = $this->lang->line('L_NAME_LAT');                    
		$this->a_validation_fields['birthday'] = $this->lang->line('BIRTHDAY');                
		$this->a_validation_fields['citizenship'] = $this->lang->line('CITIZENSHIP');                   
		$this->a_validation_fields['passp_seria'] = $this->lang->line('PASSP_SERIA');              
		$this->a_validation_fields['passp_num'] = $this->lang->line('PASSP_NUM');              
		$this->a_validation_fields['f_pass_seria'] = $this->lang->line('FPASSP_SERIA'); 
		$this->a_validation_fields['f_pass_num'] = $this->lang->line('FPASSP_NUM'); 
		$this->a_validation_fields['f_pass_period'] = $this->lang->line('FPASSP_PERIOD');
		$this->a_validation_fields['nal_number']  = $this->lang->line('NAL_NUM');           
		//$this->a_validation_fields['_cities_rid'] = $this->lang->line('CITY');                               
		$this->a_validation_fields['adress'] = $this->lang->line('ADRESS');                               
		$this->a_validation_fields['phones'] = $this->lang->line('PHONES');                         
		$this->a_validation_fields['email'] = $this->lang->line('EMAIL');  
		$this->a_validation_fields['card_num'] = $this->lang->line('CARD_NUM');                        		
		
		$this->a_validation_fields['descr'] = $this->lang->line('DESCR');
		$this->a_validation_fields['archive'] = $this->lang->line('ARCHIVE');
		$this->a_validation_fields['modifyDT'] = $this->lang->line('ARCHIVE');
		$this->validation->set_rules($this->a_validation_rules);
		$this->validation->set_fields($this->a_validation_fields);
		
		
		$this->objectsList['MENU_OBJECT'] = $this->menucontainer->RenderVerticalTreeMenu();
		
	}
	
	public function _remap($m_cif_name){
		switch ($m_cif_name) {
			case 'nJ': {echo $this->_create();break;}
			case 'eJ': {echo $this->_edit();break;}
			case 'dJ': {echo $this->_details();break;}
			case 'rJ': {echo $this->_remove();break;}
			case 'fJ'; {echo $this->_find();break;}
			case 'uJ'; {echo $this->_refresh();break;}
			case 'vJ': case'demandsJ': {$this->_vjournal();break;}
			case 'srt'; {$this->_sort();break;}
			case 'ar'; {$this->_activerecord();break;}
			case 'sar'; {$this->_setactiverecord();break;}
			case 'pg':{echo $this->_journal();break;}
			default: $this->_index();
		}
	}
	
	protected function _index(){
		$this->objectsList['GRID_OBJECT'] = $this->_journal();
		$this->load->view('layouts/main_layout', $this->objectsList);
	}
	
	public function GetTools(){
		$tools = parent::GetTools();
        //if($this->uri->segment(2)=='demandsJ') 
        $tools['picker'] = $this->load->view('demands/tools/picker', null, True);
        return $tools;
	}
	
	public function _journal(){
		
		$content = array();
		$content['title'] = $this->lang->line('DICTIONARY_TITLE'); 
		$content['rid'] = 'ID'; 
		
		$content['parent'] = $this->lang->line('PARENT');                         
		$content['f_name'] = $this->lang->line('F_NAME');                                   
		$content['s_name'] = $this->lang->line('S_NAME');                         
		$content['l_name'] = $this->lang->line('L_NAME');                           
		$content['f_name_lat'] = $this->lang->line('F_NAME_LAT');                             
		$content['l_name_lat'] = $this->lang->line('L_NAME_LAT');                    
		$content['birthday'] = $this->lang->line('BIRTHDAY');                
		$content['citizenship'] = $this->lang->line('CITIZENSHIP');                   
		$content['passp_seria'] = $this->lang->line('PASSP_SERIA');              
		$content['passp_num'] = $this->lang->line('PASSP_NUM');              
		$content['f_pass_seria'] = $this->lang->line('FPASSP_SERIA'); 
		$content['f_pass_num'] = $this->lang->line('FPASSP_NUM'); 
		$content['f_pass_period'] = $this->lang->line('FPASSP_PERIOD');
		$content['nal_number']  = $this->lang->line('NAL_NUM');           
		$content['city_name'] = $this->lang->line('CITY');                               
		$content['adress'] = $this->lang->line('ADRESS');                               
		$content['phones'] = $this->lang->line('PHONES');                         
		$content['email'] = $this->lang->line('EMAIL');   
		$content['card_num'] = $this->lang->line('CARD_NUM');            		
		// { Filters fields
		$content['filter_f_name'] = form_input(array('name'=>'f_name','id'=>'f_name', 'class'=>'input_filter'));  
		$content['filter_s_name'] = form_input(array('name'=>'s_name','id'=>'s_name', 'class'=>'input_filter')); 
		$content['filter_l_name'] = form_input(array('name'=>'l_name','id'=>'l_name', 'class'=>'input_filter')); 
		$content['filter_phones'] = form_input(array('name'=>'phones','id'=>'phones', 'class'=>'input_filter')); 
		$content['filter_email'] = form_input(array('name'=>'email','id'=>'email', 'class'=>'input_filter')); 
		$content['filter_card_num'] = form_input(array('name'=>'card_num','id'=>'card_num', 'class'=>'input_filter')); 
		// } Filters fields		
		$content['archive'] =  $this->lang->line('ARCHIVE');
		$content['modifyDT'] =  $this->lang->line('MODIFYDT');
		$content['yes'] = $this->lang->line('YES');
		$content['no'] = $this->lang->line('NO');
		$content['tools'] = $this->GetTools(); 
		$content['DS'] = $this->clients_model->GetDS();
		$content['pagination'] = $this->GetPagination();
		if(!$this->GetSessionData('activerecord')) $this->SetSessionData('activerecord', $content['DS'][0]->rid);
		$content['activerecord'] = $this->GetSessionData('activerecord');	
		//echo $content['activerecord'];
		return $this->load->view('clients/journal', $content, True);		
	}
	
	public function _vjournal(){
		$content['header'] = $this->load->view('standart/tmpl/header', array('title'=>$this->lang->line('DICTIONARY_TITLE')), True);
		$content['title'] = $this->lang->line('DICTIONARY_TITLE');
		$content['journal'] = $this->_journal();
		$this->load->view('clients/vjournal', $content);
	}
	
	public function _create(){
		if ($this->validation->run() == FALSE){
			$content = array();
			$content['header'] = $this->load->view('standart/tmpl/header', array('title'=>$this->lang->line('DICTIONARY_TITLE_CREATE')), True);
			$content['title'] = $this->lang->line('DICTIONARY_TITLE_CREATE');
						
			$clients = array(' '=>'');
			foreach($this->clients_model->GetClientsList() as $client){
				$clients[$client->rid] = $client->client_name;
			}
			# { parent 
			$content['parent'] = $this->RenderLabel('parent');
			$content['parent_field'] =  form_dropdown('parent', $clients, $this->validation->parent?$this->validation->parent:'');
			# }  parent 

			# { f_name
			$content['f_name'] = $this->RenderLabel('f_name');
			$data = array('name'=>'f_name', 'id'=>'f_name', 'size'=>'15', 'value'=>$this->validation->f_name?$this->validation->f_name:'');
			$content['f_name_field'] =  form_input($data);			                         
			# } f_name
			
			# { s_name
			$content['s_name'] = $this->RenderLabel('s_name');
			$data = array('name'=>'s_name', 'id'=>'s_name', 'size'=>'15', 'value'=>$this->validation->s_name?$this->validation->s_name:'');
			$content['s_name_field'] =  form_input($data);			                         
			# } s_name
			
			# { l_name
			$content['l_name'] = $this->RenderLabel('l_name');
			$data = array('name'=>'l_name', 'id'=>'l_name', 'size'=>'15', 'value'=>$this->validation->l_name?$this->validation->l_name:'');
			$content['l_name_field'] =  form_input($data);			                         
			# } l_name
			
			# { f_name_lat
			$content['f_name_lat'] = $this->RenderLabel('f_name_lat');
			$data = array('name'=>'f_name_lat', 'id'=>'f_name_lat', 'size'=>'15', 'value'=>$this->validation->f_name_lat?$this->validation->f_name_lat:'');
			$content['f_name_lat_field'] =  form_input($data);			                         
			# } f_name_lat
			
			# { l_name_lat
			$content['l_name_lat'] = $this->RenderLabel('l_name_lat');
			$data = array('name'=>'l_name_lat', 'id'=>'l_name_lat', 'size'=>'15', 'value'=>$this->validation->l_name_lat?$this->validation->l_name_lat:'');
			$content['l_name_lat_field'] =  form_input($data);			                         
			# } l_name_lat
			
			# { birthday
			$content['birthday'] = $this->RenderLabel('birthday');
			$data = array('name'=>'birthday', 'id'=>'birthday', 'value'=>$this->validation->birthday?$this->validation->birthday:'', 'size'=>'12', 'readonly'=>'readonly');
			$content['birthday_field'] =  form_input($data).$this->RenderCalendar('birthday');			                         
			# } birthday
			
			# { citizenship
			$content['citizenship'] = $this->RenderLabel('citizenship');
			$data = array('name'=>'citizenship', 'id'=>'citizenship', 'size'=>'15', 'value'=>$this->validation->citizenship?$this->validation->citizenship:'');
			$content['citizenship_field'] =  form_input($data);			                         
			# } citizenship
			
			# { passp_seria
			$content['passp_seria'] = $this->RenderLabel('passp_seria');
			$data = array('name'=>'passp_seria', 'id'=>'passp_seria', 'size'=>'15', 'value'=>$this->validation->passp_seria?$this->validation->passp_seria:'');
			$content['passp_seria_field'] =  form_input($data);			                         
			# } passp_seria
			
			# { passp_num
			$content['passp_num'] = $this->RenderLabel('passp_num');
			$data = array('name'=>'passp_num', 'id'=>'passp_num', 'size'=>'15', 'value'=>$this->validation->passp_num?$this->validation->passp_num:'');
			$content['passp_num_field'] =  form_input($data);			                         
			# } passp_num
			
			# { f_pass_seria
			$content['f_pass_seria'] = $this->RenderLabel('f_pass_seria');
			$data = array('name'=>'f_pass_seria', 'id'=>'f_pass_seria', 'size'=>'15', 'value'=>$this->validation->f_pass_seria?$this->validation->f_pass_seria:'');
			$content['f_pass_seria_field'] =  form_input($data);			                         
			# } f_pass_seria
			
			# { f_pass_num
			$content['f_pass_num'] = $this->RenderLabel('f_pass_num');
			$data = array('name'=>'f_pass_num', 'id'=>'f_pass_num', 'size'=>'15', 'value'=>$this->validation->f_pass_num?$this->validation->f_pass_num:'');
			$content['f_pass_num_field'] =  form_input($data);			                         
			# } f_pass_num
			
			# { f_pass_period
			$content['f_pass_period'] = $this->RenderLabel('f_pass_period');
			$data = array('name'=>'f_pass_period', 'id'=>'f_pass_period', 'value'=>$this->validation->f_pass_period?$this->validation->f_pass_period:'', 'size'=>'12', 'readonly'=>'readonly');
			$content['f_pass_period_field'] =  form_input($data).$this->RenderCalendar('f_pass_period');			                         
			# } f_pass_period
			
			# { nal_number
			$content['nal_number']  = $this->RenderLabel('nal_number');
			$data = array('name'=>'nal_number', 'id'=>'nal_number', 'size'=>'15', 'value'=>$this->validation->nal_number?$this->validation->nal_number:'');
			$content['nal_number_field'] =  form_input($data);			                         
			# } nal_number

			# { adress
			$content['adress'] = $this->RenderLabel('adress');
			$content['adress_field'] =  form_input('adress', $this->validation->adress?$this->validation->adress:'');			                         
			# } adress
			
			# { phones
			$content['phones'] = $this->RenderLabel('phones');
			$data = array('name'=>'phones', 'id'=>'phones', 'size'=>'15', 'value'=>$this->validation->phones?$this->validation->phones:'');
			$content['phones_field'] =  form_input($data);			                         
			# } phones
			
			# { email
			$content['email'] = $this->RenderLabel('email');
			$data = array('name'=>'email', 'id'=>'email', 'size'=>'15', 'value'=>$this->validation->email?$this->validation->email:'');
			$content['email_field'] =  form_input($data);			                         
			# } email
			
			# { card_num
			$content['card_num'] = $this->RenderLabel('card_num');
			$data = array('name'=>'card_num', 'id'=>'card_num', 'size'=>'15', 'value'=>$this->validation->card_num?$this->validation->card_num:'');
			$content['card_num_field'] =  form_input($data);			                         
			# } card_num
			
			# { descr
			$content['descr'] =  $this->lang->line('DESCR');
			$data = array('name'=>'descr', 'id'=>'descr', 'cols'=>'50', 'rows'=>'2', 'value'=>$this->validation->descr?$this->validation->descr:''); 
			$content['descr_field'] =  form_textarea($data);
			# } descr

			# { archive
			$content['archive'] =  $this->lang->line('ARCHIVE');
			$content['archive_field'] =  form_dropdown('archive', array('0'=>$this->lang->line('NO'), '1'=>$this->lang->line('YES')), $this->validation->archive?$this->validation->archive:'');
			# } archive
			
			# { modifyDT
			$content['modifyDT'] =  $this->lang->line('MODIFYDT');
			$content['modifyDT_field'] =  form_input('modifyDT', $this->validation->modifyDT?$this->validation->modifyDT:'');
			# } modifyDT
			return $this->load->view('clients/create', $content, True);
		}
		if($insRid = $this->clients_model->CreateRecord()){
			$this->SetSessionData('activerecord', $insRid);
			$this->load->view('standart/tmpl/create_success', array('identifier'=>$this->GetIdentifier()));
		}
	}
	
	public function _edit(){
		if($activerecord=$this->uri->segment(3)) $this->_setactiverecord($activerecord);
		if ($this->validation->run() == FALSE){
			$content = array();
			$content['DS'] = $this->clients_model->GetEditDS();
			$content['header'] = $this->load->view('standart/tmpl/header', array('title'=>$this->lang->line('DICTIONARY_TITLE_EDIT')), True);
			$content['title'] = $this->lang->line('DICTIONARY_TITLE_EDIT');
			
			# { parent 	
			$clients = array(' '=>'');
			foreach($this->clients_model->GetClientsList() as $client){
				$clients[$client->rid] = $client->client_name;
			}
			$content['parent'] = $this->RenderLabel('parent');;
			$content['parent_field'] =  form_dropdown('parent', $clients, $this->validation->parent?$this->validation->parent:$content['DS']->parent);
			# } parent
			
			# { f_name
			$content['f_name'] = $this->RenderLabel('f_name');
			$data = array('name'=>'f_name', 'id'=>'f_name', 'size'=>'15', 'value'=>$this->validation->f_name?$this->validation->f_name:$content['DS']->f_name);
			$content['f_name_field'] =  form_input($data);			                         
			# } f_name
			
			# { s_name
			$content['s_name'] = $this->RenderLabel('s_name');
			$data = array('name'=>'s_name', 'id'=>'s_name', 'size'=>'15', 'value'=>$this->validation->s_name?$this->validation->s_name:$content['DS']->s_name);
			$content['s_name_field'] =  form_input($data);			                         
			# } s_name
			
			# { l_name
			$content['l_name'] = $this->RenderLabel('l_name');
			$data = array('name'=>'l_name', 'id'=>'l_name', 'size'=>'15', 'value'=>$this->validation->l_name?$this->validation->l_name:$content['DS']->l_name);
			$content['l_name_field'] =  form_input($data);			                         
			# } l_name
			
			# { f_name_lat
			$content['f_name_lat'] = $this->RenderLabel('f_name_lat');
			$data = array('name'=>'f_name_lat', 'id'=>'f_name_lat', 'size'=>'15', 'value'=>$this->validation->f_name_lat?$this->validation->f_name_lat:$content['DS']->f_name_lat);
			$content['f_name_lat_field'] =  form_input($data);			                         
			# } f_name_lat
			
			# { l_name_lat
			$content['l_name_lat'] = $this->RenderLabel('l_name_lat');
			$data = array('name'=>'l_name_lat', 'id'=>'l_name_lat', 'size'=>'15', 'value'=>$this->validation->l_name_lat?$this->validation->l_name_lat:$content['DS']->l_name_lat);
			$content['l_name_lat_field'] =  form_input($data);			                         
			# } l_name_lat
			
			# { birthday
			$content['birthday'] = $this->RenderLabel('birthday');
			$data = array('name'=>'birthday', 'id'=>'birthday', 'value'=>$this->validation->birthday?$this->validation->birthday:$content['DS']->birthday, 'size'=>'12', 'readonly'=>'readonly');
			$content['birthday_field'] =  form_input($data).$this->RenderCalendar('birthday');			                         
			# } birthday
			
			# { citizenship
			$content['citizenship'] = $this->RenderLabel('citizenship');
			$data = array('name'=>'citizenship', 'id'=>'citizenship', 'size'=>'15', 'value'=>$this->validation->citizenship?$this->validation->citizenship:$content['DS']->citizenship);
			$content['citizenship_field'] =  form_input($data);			                         
			# } citizenship

			# { passp_seria			
			$content['passp_seria'] = $this->RenderLabel('passp_seria');
			$data = array('name'=>'passp_seria', 'id'=>'passp_seria', 'size'=>'15', 'value'=>$this->validation->passp_seria?$this->validation->passp_seria:$content['DS']->passp_seria);
			$content['passp_seria_field'] =  form_input($data);			                         
			# } passp_seria
			
			# { passp_num
			$content['passp_num'] = $this->RenderLabel('passp_num');
			$data = array('name'=>'passp_num', 'id'=>'passp_num', 'size'=>'15', 'value'=>$this->validation->passp_num?$this->validation->passp_num:$content['DS']->passp_num);
			$content['passp_num_field'] =  form_input($data);			                         
			# } passp_num
			
			# { f_pass_seria
			$content['f_pass_seria'] = $this->RenderLabel('f_pass_seria');
			$data = array('name'=>'f_pass_seria', 'id'=>'f_pass_seria', 'size'=>'15', 'value'=>$this->validation->f_pass_seria?$this->validation->f_pass_seria:$content['DS']->f_pass_seria);
			$content['f_pass_seria_field'] =  form_input($data);			                         
			# } f_pass_seria
			
			# { f_pass_num
			$content['f_pass_num'] = $this->RenderLabel('f_pass_num');
			$data = array('name'=>'f_pass_num', 'id'=>'f_pass_num', 'size'=>'15', 'value'=>$this->validation->f_pass_num?$this->validation->f_pass_num:$content['DS']->f_pass_num);
			$content['f_pass_num_field'] =  form_input($data);			                         
			# } f_pass_num
			
			# { f_pass_period
			$content['f_pass_period'] = $this->RenderLabel('f_pass_period');
			$data = array('name'=>'f_pass_period', 'id'=>'f_pass_period', 'value'=>$this->validation->f_pass_period?$this->validation->f_pass_period:$content['DS']->f_pass_period, 'size'=>'12', 'readonly'=>'readonly');
			$content['f_pass_period_field'] =  form_input($data).$this->RenderCalendar('f_pass_period');			                         
			# } f_pass_period
			
			# { nal_number
			$content['nal_number']  = $this->RenderLabel('nal_number');
			$data = array('name'=>'nal_number', 'id'=>'nal_number', 'size'=>'15', 'value'=>$this->validation->nal_number?$this->validation->nal_number:$content['DS']->nal_number);
			$content['nal_number_field'] =  form_input($data);			                         
			# } nal_number
			
			# { adress
			$content['adress'] = $this->RenderLabel('adress');
			$content['adress_field'] =  form_input('adress', $this->validation->adress?$this->validation->adress:$content['DS']->adress);			                         
			# } adress
			
			# { phones
			$content['phones'] = $this->RenderLabel('phones');
			$data = array('name'=>'phones', 'id'=>'phones', 'size'=>'15', 'value'=>$this->validation->phones?$this->validation->phones:$content['DS']->phones);
			$content['phones_field'] =  form_input($data);			                         
			# } phones
			
			# { email
			$content['email'] = $this->RenderLabel('email');
			$data = array('name'=>'email', 'id'=>'email', 'size'=>'15', 'value'=>$this->validation->email?$this->validation->email:$content['DS']->email);
			$content['email_field'] =  form_input($data);
			# } email

			# { card_num
			$content['card_num'] = $this->RenderLabel('card_num');
			$data = array('name'=>'card_num', 'id'=>'card_num', 'size'=>'15', 'value'=>$this->validation->card_num?$this->validation->card_num:$content['DS']->card_num);
			$content['card_num_field'] =  form_input($data);			                         
			# } card_num
			
			# { descr
			$content['descr'] =  $this->lang->line('DESCR');
			$data = array('name'=>'descr', 'id'=>'descr', 'cols'=>'50', 'rows'=>'2', 'value'=>$this->validation->descr?$this->validation->descr:$content['DS']->descr); 
			$content['descr_field'] =  form_textarea($data);
			# } descr

			# { archive
			$content['archive'] =  $this->lang->line('ARCHIVE');
			$content['archive_field'] =  form_dropdown('archive', array('0'=>$this->lang->line('NO'), '1'=>$this->lang->line('YES')), $this->validation->archive?$this->validation->archive:$content['DS']->archive);
			# } archive
			
			# { modifyDT
			$content['modifyDT'] =  $this->lang->line('MODIFYDT');
			$content['modifyDT_field'] =  form_input('modifyDT', $this->validation->modifyDT?$this->validation->modifyDT:$content['DS']->modifyDT);
			# } modifyDT
			return $this->load->view('clients/edit', $content, True);
		}
		if($this->clients_model->UpdateRecord()){
			$this->load->view('standart/tmpl/edit_success', array('identifier'=>$this->GetIdentifier()));
		}
	}
	
	public function _details(){
			if($activerecord=$this->uri->segment(3)) $this->_setactiverecord($activerecord);
			$content = array();
			$content['DS'] = $this->clients_model->GetEditDS();
			$content['header'] = $this->load->view('standart/tmpl/header', array('title'=>$this->lang->line('DICTIONARY_TITLE_DETAILS')), True);
			$content['title'] = $this->lang->line('DICTIONARY_TITLE_DETAILS');
			# { parent 	
			$clients = array(' '=>'');
			foreach($this->clients_model->GetClientsList() as $client){
				$clients[$client->rid] = $client->client_name;
			}
			$content['parent'] = $this->RenderLabel('parent');;
			$content['parent_field'] =  form_dropdown('parent', $clients, $this->validation->parent?$this->validation->parent:$content['DS']->parent);
			# } parent
			
			# { f_name
			$content['f_name'] = $this->RenderLabel('f_name');
			$data = array('name'=>'f_name', 'id'=>'f_name', 'size'=>'15', 'value'=>$this->validation->f_name?$this->validation->f_name:$content['DS']->f_name);
			$content['f_name_field'] =  form_input($data);			                         
			# } f_name
			
			# { s_name
			$content['s_name'] = $this->RenderLabel('s_name');
			$data = array('name'=>'s_name', 'id'=>'s_name', 'size'=>'15', 'value'=>$this->validation->s_name?$this->validation->s_name:$content['DS']->s_name);
			$content['s_name_field'] =  form_input($data);			                         
			# } s_name
			
			# { l_name
			$content['l_name'] = $this->RenderLabel('l_name');
			$data = array('name'=>'l_name', 'id'=>'l_name', 'size'=>'15', 'value'=>$this->validation->l_name?$this->validation->l_name:$content['DS']->l_name);
			$content['l_name_field'] =  form_input($data);			                         
			# } l_name
			
			# { f_name_lat
			$content['f_name_lat'] = $this->RenderLabel('f_name_lat');
			$data = array('name'=>'f_name_lat', 'id'=>'f_name_lat', 'size'=>'15', 'value'=>$this->validation->f_name_lat?$this->validation->f_name_lat:$content['DS']->f_name_lat);
			$content['f_name_lat_field'] =  form_input($data);			                         
			# } f_name_lat
			
			# { l_name_lat
			$content['l_name_lat'] = $this->RenderLabel('l_name_lat');
			$data = array('name'=>'l_name_lat', 'id'=>'l_name_lat', 'size'=>'15', 'value'=>$this->validation->l_name_lat?$this->validation->l_name_lat:$content['DS']->l_name_lat);
			$content['l_name_lat_field'] =  form_input($data);			                         
			# } l_name_lat
			
			# { birthday
			$content['birthday'] = $this->RenderLabel('birthday');
			$data = array('name'=>'birthday', 'id'=>'birthday', 'value'=>$this->validation->birthday?$this->validation->birthday:$content['DS']->birthday, 'size'=>'12', 'readonly'=>'readonly');
			$content['birthday_field'] =  form_input($data).$this->RenderCalendar('birthday');			                         
			# } birthday
			
			# { citizenship
			$content['citizenship'] = $this->RenderLabel('citizenship');
			$data = array('name'=>'citizenship', 'id'=>'citizenship', 'size'=>'15', 'value'=>$this->validation->citizenship?$this->validation->citizenship:$content['DS']->citizenship);
			$content['citizenship_field'] =  form_input($data);			                         
			# } citizenship

			# { passp_seria			
			$content['passp_seria'] = $this->RenderLabel('passp_seria');
			$data = array('name'=>'passp_seria', 'id'=>'passp_seria', 'size'=>'15', 'value'=>$this->validation->passp_seria?$this->validation->passp_seria:$content['DS']->passp_seria);
			$content['passp_seria_field'] =  form_input($data);			                         
			# } passp_seria
			
			# { passp_num
			$content['passp_num'] = $this->RenderLabel('passp_num');
			$data = array('name'=>'passp_num', 'id'=>'passp_num', 'size'=>'15', 'value'=>$this->validation->passp_num?$this->validation->passp_num:$content['DS']->passp_num);
			$content['passp_num_field'] =  form_input($data);			                         
			# } passp_num
			
			# { f_pass_seria
			$content['f_pass_seria'] = $this->RenderLabel('f_pass_seria');
			$data = array('name'=>'f_pass_seria', 'id'=>'f_pass_seria', 'size'=>'15', 'value'=>$this->validation->f_pass_seria?$this->validation->f_pass_seria:$content['DS']->f_pass_seria);
			$content['f_pass_seria_field'] =  form_input($data);			                         
			# } f_pass_seria
			
			# { f_pass_num
			$content['f_pass_num'] = $this->RenderLabel('f_pass_num');
			$data = array('name'=>'f_pass_num', 'id'=>'f_pass_num', 'size'=>'15', 'value'=>$this->validation->f_pass_num?$this->validation->f_pass_num:$content['DS']->f_pass_num);
			$content['f_pass_num_field'] =  form_input($data);			                         
			# } f_pass_num
			
			# { f_pass_period
			$content['f_pass_period'] = $this->RenderLabel('f_pass_period');
			$data = array('name'=>'f_pass_period', 'id'=>'f_pass_period', 'value'=>$this->validation->f_pass_period?$this->validation->f_pass_period:$content['DS']->f_pass_period, 'size'=>'12', 'readonly'=>'readonly');
			$content['f_pass_period_field'] =  form_input($data).$this->RenderCalendar('f_pass_period');			                         
			# } f_pass_period
			
			# { nal_number
			$content['nal_number']  = $this->RenderLabel('nal_number');
			$data = array('name'=>'nal_number', 'id'=>'nal_number', 'size'=>'15', 'value'=>$this->validation->nal_number?$this->validation->nal_number:$content['DS']->nal_number);
			$content['nal_number_field'] =  form_input($data);			                         
			# } nal_number
			
			# { adress
			$content['adress'] = $this->RenderLabel('adress');
			$content['adress_field'] =  form_input('adress', $this->validation->adress?$this->validation->adress:$content['DS']->adress);			                         
			# } adress
			
			# { phones
			$content['phones'] = $this->RenderLabel('phones');
			$data = array('name'=>'phones', 'id'=>'phones', 'size'=>'15', 'value'=>$this->validation->phones?$this->validation->phones:$content['DS']->phones);
			$content['phones_field'] =  form_input($data);			                         
			# } phones
			
			# { email
			$content['email'] = $this->RenderLabel('email');
			$data = array('name'=>'email', 'id'=>'email', 'size'=>'15', 'value'=>$this->validation->email?$this->validation->email:$content['DS']->email);
			$content['email_field'] =  form_input($data);
			# } email

			# { card_num
			$content['card_num'] = $this->RenderLabel('card_num');
			$data = array('name'=>'card_num', 'id'=>'card_num', 'size'=>'15', 'value'=>$this->validation->card_num?$this->validation->card_num:$content['DS']->card_num);
			$content['card_num_field'] =  form_input($data);			                         
			# } card_num
						
			# { descr
			$content['descr'] =  $this->lang->line('DESCR');
			$data = array('name'=>'descr', 'id'=>'descr', 'cols'=>'50', 'rows'=>'2', 'value'=>$this->validation->descr?$this->validation->descr:$content['DS']->descr); 
			$content['descr_field'] =  form_textarea($data);
			# } descr

			# { archive
			$content['archive'] =  $this->lang->line('ARCHIVE');
			$content['archive_field'] =  form_dropdown('archive', array('0'=>$this->lang->line('NO'), '1'=>$this->lang->line('YES')), $this->validation->archive?$this->validation->archive:$content['DS']->archive);
			# } archive
			
			# { modifyDT
			$content['modifyDT'] =  $this->lang->line('MODIFYDT');
			$content['modifyDT_field'] =  form_input('modifyDT', $this->validation->modifyDT?$this->validation->modifyDT:$content['DS']->modifyDT);
			# } modifyDT
			return $this->load->view('clients/details', $content, True);
	}

	public function _remove(){
		if($activerecord=$this->uri->segment(3)) $this->_setactiverecord($activerecord);
		$this->clients_model->DeleteRecord();
		$this->SetSessionData('activerecord', null);
		echo $this->_journal();
	}
	
	public function _find(){
		if (!isset($_POST['goFind'])){
			$content = array();
			$content['header'] = $this->load->view('standart/tmpl/header', array('title'=>$this->lang->line('DICTIONARY_TITLE_FIND')), True);
			$content['title'] = $this->lang->line('DICTIONARY_TITLE_FIND');
						
			$content['f_name'] = $this->lang->line('F_NAME');
			$content['f_name_field'] =  form_input('f_name', $this->validation->f_name?$this->validation->f_name:'');			                         
			/*
			$content['s_name'] = $this->lang->line('S_NAME');
			$content['s_name_field'] =  form_input('s_name', $this->validation->s_name?$this->validation->s_name:'');			                         
			*/
			$content['l_name'] = $this->lang->line('L_NAME');
			$content['l_name_field'] =  form_input('l_name', $this->validation->l_name?$this->validation->l_name:'');			                         
			
			$content['phones'] = $this->lang->line('PHONES');
			$content['phones_field'] =  form_input('phones', $this->validation->phones?$this->validation->phones:'');			                         
			
			$content['email'] = $this->lang->line('EMAIL');
			$content['email_field'] =  form_input('email', $this->validation->email?$this->validation->email:'');			                         
			
			$content['card_num'] = $this->lang->line('CARD_NUM');
			$content['card_num_field'] =  form_input('card_num', $this->validation->card_num?$this->validation->card_num:'');			                         
			
			return $this->load->view('clients/find', $content, True);
		}
		$searchRule = array();
		if(isset($_POST['rid']) && trim($_POST['rid'])) $searchRule['_clients.rid'] = trim($_POST['rid']);
		if(isset($_POST['f_name']) && trim($_POST['f_name'])) $searchRule['_clients.f_name'] = trim($_POST['f_name']);
		//if(trim($_POST['s_name'])) $searchRule['_clients.s_name'] = trim($_POST['s_name']);
		if(isset($_POST['l_name']) && trim($_POST['l_name'])) $searchRule['_clients.l_name'] = trim($_POST['l_name']);
		if(isset($_POST['phones']) && trim($_POST['phones'])) $searchRule['_clients.phones'] = trim($_POST['phones']);
		if(isset($_POST['email']) && trim($_POST['email'])) $searchRule['_clients.email'] = trim($_POST['email']);
		if(isset($_POST['card_num']) && trim($_POST['card_num'])) $searchRule['_clients.card_num'] = trim($_POST['card_num']);
		if($searchRule){
			$this->_setsearchrule($searchRule);
		}
		if($_POST['goFind']=='2'){
			redirect('clients', 'refresh');
		}
		$this->load->view('standart/tmpl/find_success', array('identifier'=>$this->GetIdentifier()));
	}
	
	public function _refresh(){
		$this->RefreshSessionData();
		echo $this->_journal();
	}
	
}

?>